![]() | Editing Optimization Objects | Guidelines on optimization parameters | ![]() |
To modify the Optimization Definition properties highlight the top line of the optimization tree in the left hand pane of the Multiple Object Editor:
The properties will be displayed in the right hand pane:
Direction: The radio button can be set to Maximise or to Minimise the cost function. In the example above, the value will be held in the numeric variable cost.
Number of Generations: The basic property that defines the number of generations to be created and evaluated during the evolution cycle. A default value of 50 is used but 10 as a good initial value to test that the cost variable is improving with advancing generations.
Number of Individuals: This property defines the number of individuals that will be evaluated per generation. It should be set between 50 and 100 depending on the total number of genes in all chromosomes. A default value of 50 can be adequate for up to 20 genes but consider increasing this for a larger number of genes.
Crossover probability: Determines the level of probability of the child (new) individual that is created from two parents being identical to or resembling the first parent. The higher the value the less likely the child individual is to resemble the first parent. The default value is 0.2
Mutation probability: Determines the probability of a newly created individual having the value of some of its genes randomly changed. The default mutation value is .050
Cost Gradient: When creating a new generation from an existing one, the probability of selecting an existing chromosome as a parent is proportional to the cost of that chromosome relative to the rest of the population. In other words, good chromosomes have more chances of becoming parents of future generations. How much we discriminate in favour of good chromosomes in our selection of parents depends on the cost gradient. A cost gradient of 0 gives all chromosomes a chance to be parents, while a higher cost gradient favours good parents. The default value is 2.
Runtime Display: Full Graph: By default a full dialog box will appear during optimization, showing the current generation number along with other useful optimization information. There is also an option to pause at the end of the optimisation. The final information is displayed on the graph until the OK button is clicked
Runtime Display: Progress: A reduced 'bare minimum' display showing only the generation number and the percentage of individuals processed within the generation.
Events
These events fire at different times during the optimisation process and can be programmed like any other procedure function using the Knowledge Builder @Commands.
Optimization Start
This event fires immediately prior to the start of the optimization process and is the ideal place to put optimization initialisation code. For example, the Tsp_Adaptation Knowledge Module in samples Optimise project:
@Do Build_Data
@Assign Start_Mutation_Level = TSP_Opt.mutation
@Assign prevCost = 99999999
Notice also that because the mutation probability is changed during the optimisation process the original value is stored so that it can be restored at the end of the optimization. See Optimization End below.
Optimization End
This event fires at the end of the optimisation process and is ideal for updating data based on the optimisation results. For example, the TSP Knowledge Module in samples Optimise project:
Function ( bestCost:N )
@Do Update_Data
@Assign TSP_Opt.mutation = Start_Mutation_Level
Notice also that the mutation probability is restored to its original value. See Optimization Start above.
Generation Start
This function fires at the start of a generation. The generation number (genNo) is passed to the event as a function parameter:
Function ( genNo:N )
The function does not require a return value.
Generation End
This event fires at the end of a generation and can have many uses. The gene values are available as exposed properties in this event and the generation number (genNo), the cost value of the best individual in the generation (bestCost) and the average cost of all the individuals in the generation (avgCost) are passed to the event as function parameters. If the function returns TRUE (@Return TRUE) then the optimisation process will continue providing the maximum number of generations has not been reached. If the function returns FALSE (@Return FALSE) the optimisation process is terminated.
In the Tsp_Adaptation Knowledge Module in samples Optimise project an adaptation strategy is used. Adaptation strategy involves the adjustment of the optimisation parameters dynamically during the optimisation process and this sample increases the mutation probability after a number of generations have failed to improve the cost. The logic being that if the system is failing to find a better result then adding more randomness may pop up a better individual and cause the system to start to explore in a new area of the search space.
In Tsp_Adaptation the mutation probability is changed during the optimisation process so the original value is stored in the variable Start_Mutation_Level – see event Optimisation Start above. Also the variable prevCost is initialised to a number that is higher than any possible cost result. The Generation End event code is shown below:
Function ( genNo:N , bestCost:N , avgCost:N ) : B
@Return TRUE
@If bestCost < prevCost
@Assign prevCost = bestCost
@Assign CostCount = 0
@Assign TSP_Opt.mutation = Start_Mutation_Level
@Else
@Assign CostCount = CostCount + 1
@If CostCount = 10
@Assign TSP_Opt.mutation = TSP_Opt.mutation + (Start_Mutation_Level / 4)
@Assign CostCount = 0
@EndIf
@EndIf
If the system fails to improve the cost for 10 generations the mutation probability is increased by Start_Mutation_Level / 4. If the cost has not improved after a further 10 generations then the mutation probability is increased again and so on. Every time the cost is improved the mutation probability is reset to its original pre-set value and the counter (CostCount) set to zero.
This event could also be used to terminate an optimisation process if the cost result has not improved after a number of generations on the assumption that there is unlikely to be any further improvement. The code could look something like:
Function ( genNo:N , bestCost:N , avgCost:N ) : B
@Return TRUE
@If bestCost < prevCost
@Assign prevCost = bestCost
@Assign CostCount = 0
@Else
@Assign CostCount = CostCount + 1
@If CostCount = 50
@Return FALSE
@EndIf
@EndIf
Note the use of @Return FALSE to terminate the optimisation